{{!

  Copyright (c) Facebook, Inc. and its affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}{{!

Generates external type annotations for legacy Thrift files.

}}
{{> common/AutoGeneratedPy}}

# pyre-unsafe

import typing as __T  # sometimes `t` is used as a field name

from thrift import Thrift
from thrift.protocol.TProtocol import TProtocolBase

__property__ = property  # sometimes `property` is used as a field name

{{#program:includeNamespaces}}
{{#hasTypes?}}
import {{#includeNamespace}}{{value}}.{{/includeNamespace}}ttypes
{{/hasTypes?}}
{{/program:includeNamespaces}}

UTF8STRINGS: bool
{{#program:enums}}


class {{enum:name}}(int):
    {{#enum:values}}
    {{enumValue:name}}: __T.ClassVar[{{enum:name}}]
    {{/enum:values}}

    _VALUES_TO_NAMES: __T.ClassVar[__T.Dict[{{enum:name}}, str]]
    _NAMES_TO_VALUES: __T.ClassVar[__T.Dict[str, {{enum:name}}]]
{{/program:enums}}
{{#program:structs}}


class {{struct:name}}{{#struct:exception?}}(Thrift.TException){{/struct:exception?}}:
    thrift_spec: __T.Tuple[__T.Optional[__T.Tuple[int, int, str, __T.Any, __T.Optional[int], int]]]
    thrift_field_annotations: __T.Dict[int, __T.Dict[str, str]]
    thrift_struct_annotations: __T.Dict[str, str]

    def __init__(
        self{{#struct:fields}},
        {{field:name}}: {{#field:type}}{{> common/OptionalFieldType}}{{/field:type}} = ...{{/struct:fields}}
    ) -> None:
        ...

    {{#struct:fields}}
    {{#field:type}}
    @__property__
    def {{field:name}}(self) -> {{#field:PEP484Optional?}}__T.Optional[{{/field:PEP484Optional?}}{{!
    }}{{> common/FieldType}}{{#field:PEP484Optional?}}]{{/field:PEP484Optional?}}: ...
    @{{field:name}}.setter
    def {{field:name}}(self, value: {{> common/OptionalFieldType}}) -> None: ...
    {{/field:type}}
    {{/struct:fields}}

    {{#struct:union?}}
    def getType(self) -> int: ...

    {{#struct:fields}}
    {{#field:type}}
    def get_{{field:name}}(self) -> {{> common/FieldType}}: ...
    def set_{{field:name}}(self, value: {{> common/FieldType}}) -> None: ...
    {{/field:type}}
    {{/struct:fields}}

    __EMPTY__: int = ...
    {{#struct:fields}}
    {{#field:type}}
    {{field:capitalizedName}}: int = ...
    {{/field:type}}
    {{/struct:fields}}
    {{/struct:union?}}

    def isUnion(self) -> bool: ...
    def checkRequired(self) -> None: ...
    def read(self, iprot: TProtocolBase) -> None: ...
    {{#program:json?}}
    @__T.overload
    def readFromJson(self, json: __T.Dict[str, __T.Any], is_text: bool = ...) -> None: ...
    @__T.overload
    def readFromJson(self, json: str, is_text: bool = ...) -> None: ...
    {{/program:json?}}
    def write(self, oprot: TProtocolBase) -> None: ...
    def __eq__(self, other: __T.Any) -> bool: ...
    def __ne__(self, other: __T.Any) -> bool: ...
{{/program:structs}}


{{#program:typedefs}}
{{typedef:symbolic}} = {{#typedef:type}}{{> common/FieldType}}{{/typedef:type}}
{{/program:typedefs}}
